var __extends =
    (this && this.__extends) ||
    (function () {
      var e = function (t, i) {
        return (e =
          Object.setPrototypeOf ||
          ({ __proto__: [] } instanceof Array &&
            function (e, t) {
              e.__proto__ = t;
            }) ||
          function (e, t) {
            for (var i in t)
              Object.prototype.hasOwnProperty.call(t, i) && (e[i] = t[i]);
          })(t, i);
      };
      return function (t, i) {
        function o() {
          this.constructor = t;
        }
        if ("function" != typeof i && null !== i)
          throw new TypeError(
            "Class extends value " + String(i) + " is not a constructor or null"
          );
        e(t, i),
          (t.prototype =
            null === i
              ? Object.create(i)
              : ((o.prototype = i.prototype), new o()));
      };
    })(),
  RegDialog = (function (e) {
    function t() {
      var t = e.call(this) || this;
      (t.def_time = 60),
        (t.dataArr = []),
        (Laya.loader.retryNum = 2),
        t.pos(0, 0.5 * (Laya.stage.height - 350)),
        t.tab_loginReg.on(Laya.Event.CLICK, t, t.onTabSelect),
        t.loginGame.on(Laya.Event.CLICK, t, t.loginFn),
        t.bt_reginster.on(Laya.Event.CLICK, t, t.registerFn),
        t.bt_phoneCode.on(Laya.Event.CLICK, t, t.verificateCodeFn),
        t.btn_fogetScrect.on(Laya.Event.CLICK, t, t.onForgetFn),
        t.btn_submitpwd.on(Laya.Event.CLICK, t, t.submitpwdFn),
        t.btn_forBack.on(Laya.Event.CLICK, t, t.forgetBackFn),
        t.btn_getCode.on(Laya.Event.CLICK, t, t.modifypwdCodeFn),
        t.img_captcha.on(Laya.Event.CLICK, t, t.changeRegImage),
        t.btn_getCaptcha.on(Laya.Event.CLICK, t, t.changeRegImage),
        t.img_captcha2.on(Laya.Event.CLICK, t, t.changeImage),
        t.btn_getCaptcha2.on(Laya.Event.CLICK, t, t.changeImage),
        t.btn_down_more.on(Laya.Event.CLICK, t, t.onDidDownMoreAction),
        (t.list_more_phone.vScrollBarSkin = ""),
        (t.list_more_phone.selectEnable = !0),
        t.list_more_phone.on(Laya.Event.CLICK, t, t.onDidMoreListAction),
        (t.remmbercheckBox.selected = !0),
        (t.tx_account.restrict = "0-9||a-zA-Z"),
        (t.tx_phoneNum.restrict = "0-9"),
        (t.phone.restrict = "0-9"),
        (t.tx_verificateCode.restrict = "0-9||a-zA-Z"),
        (t.tx_captcha.restrict = "0-9||a-zA-Z"),
        (t.tx_captcha2.restrict = "0-9||a-zA-Z");
      var i = laya.net.LocalStorage.getItem("mobileText"),
        o = laya.net.LocalStorage.getItem("passwordText");
      return (
        i ? (t.tx_account.text = i) : (t.tx_account.prompt = "请输入账号"),
        o ? (t.tx_password.text = o) : (t.tx_password.prompt = "请输入账号"),
        t
      );
    }
    return (
      __extends(t, e),
      (t.prototype.initView = function () {}),
      (t.showLoginAndRegView = function () {
        null == this.regDialogView && (this.regDialogView = new t()),
          this.regDialogView.popup(!0),
          (this.regDialogView.def_time = 60),
          (this.regDialogView.list_more_phone.visible = !1),
          (this.regDialogView.registerView.visible = !0),
          (this.regDialogView.forgetpwdView.visible = !1),
          (this.regDialogView.loginView.visible = !0),
          (this.regDialogView.tab_loginReg.selectedIndex = 0),
          (this.regDialogView.registerView.visible = !1),
          (this.regDialogView.loginView.visible = !0),
          (this.regDialogView.tx_phoneNum.text = ""),
          (this.regDialogView.tx_pwd.text = ""),
          (this.regDialogView.tx_aginspassword.text = ""),
          (this.regDialogView.tx_verificateCode.text = ""),
          (this.regDialogView.tx_captcha.text = "");
        var e = laya.net.LocalStorage.getItem("code");
        return (
          e &&
            ((this.regDialogView.tx_code.text = e),
            (this.regDialogView.tx_code.disabled = !0)),
          this.regDialogView
        );
      }),
      (t.prototype.onTabSelect = function (e) {
        this.list_more_phone.visible = !1;
        0 == ("item0" == e.target.name ? 0 : 1)
          ? ((this.registerView.visible = !1),
            (this.loginView.visible = !0),
            (this.btn_down_more.visible = !0))
          : ((this.registerView.visible = !0),
            (this.loginView.visible = !1),
            (this.btn_down_more.visible = !1));
      }),
      (t.prototype.loginFn = function () {
        var e = this.tx_account.text,
          t = this.tx_password.text;
        if (((this.list_more_phone.visible = !1), e))
          if (t) {
            laya.net.LocalStorage.setItem("mobileText", e),
              this.saveLocalAccount(e, t);
            var i = new Ajax(this),
              o = { mobile: e, pwd: Md5.hashStr(t), captcha: "1234" };
            (i.success = this.loginSuccess),
              i.post(Environment.apiHost + "/user-service/user/login", o),
              this.close();
          } else ToastView.toastView("请输入密码");
        else ToastView.toastView("请输入账号");
      }),
      (t.prototype.saveLocalAccount = function (e, t) {
        var i = laya.net.LocalStorage.getJSON("localAcc"),
          o = [],
          s = { phone: e, password: t },
          a = JSON.stringify(s);
        if ((o.unshift(a), i && i.length > 0))
          for (var n = 0; n < i.length; n++) {
            var r = i[n];
            o.length < 3 && -1 === o.indexOf(r) && o.push(r);
          }
        laya.net.LocalStorage.setJSON("localAcc", o);
      }),
      (t.prototype.onDidDownMoreAction = function () {
        var e = laya.net.LocalStorage.getJSON("localAcc");
        if (0 == this.list_more_phone.visible) {
          if (((this.btn_down_more.label = "△"), e && e.length > 0)) {
            this.list_more_phone.visible = !0;
            var t = void 0;
            this.dataArr = [];
            for (var i = 0; i < e.length; i++) {
              var o = e[i],
                s = {};
              o && (s = JSON.parse(o)),
                (t = {
                  item0: { text: s.phone },
                  phone: s.phone,
                  password: s.password,
                }),
                this.dataArr.push(t);
            }
            this.list_more_phone.dataSource = this.dataArr;
          }
        } else
          (this.btn_down_more.label = "▽"), (this.list_more_phone.visible = !1);
      }),
      (t.prototype.onDidMoreListAction = function (e) {
        if ("" != e.target.name) {
          var t = this.list_more_phone.selectedItem;
          (this.list_more_phone.visible = !1),
            (this.btn_down_more.label = "▽"),
            t.phone &&
              ((this.tx_account.text = t.phone),
              (this.tx_password.text = t.password));
        }
      }),
      (t.prototype.loginSuccess = function (e) {
        if ((console.log(e), 0 == e.code)) {
          laya.net.LocalStorage.setItem("passwordText", this.tx_password.text),
            laya.net.LocalStorage.setItem("userId", e.data.userId),
            laya.net.LocalStorage.setItem("accessToken", e.data.accessToken),
            laya.net.LocalStorage.setItem("loginTime", Date.now().toString()),
            this.close();
          var t = ServerListView.openServerListView();
          Laya.stage.addChild(t),
            Laya.stage.removeChildByName("LoginView"),
            this.removeSelf();
        } else ToastView.toastView(e.msg);
      }),
      (t.prototype.registerFn = function () {
        var e = this.tx_phoneNum.text,
          t = this.tx_pwd.text,
          i = this.tx_aginspassword.text,
          o = this.tx_verificateCode.text;
        if (e)
          if (t)
            if (i)
              if (o)
                if (t == i) {
                  var s = new Ajax(this),
                    a = {
                      mobile: e,
                      pwd: Md5.hashStr(t),
                      captcha: o,
                      channel: null,
                      code: null,
                    },
                    n = this.tx_code.text;
                  n && (a.code = n);
                  var r = laya.net.LocalStorage.getItem("channel");
                  r && (a.channel = r),
                    (s.success = this.registerSuccess),
                    s.post(
                      Environment.apiHost + "/user-service/user/register",
                      a
                    );
                } else ToastView.toastView("两次密码输入不一样");
              else ToastView.toastView("请输入验证码");
            else ToastView.toastView("请输入确认密码");
          else ToastView.toastView("请输入密码");
        else ToastView.toastView("请输入账号");
      }),
      (t.prototype.timeCountDown = function () {
        this.def_time--,
          (this.bt_phoneCode.label = "重新获取" + this.def_time + "s"),
          (this.bt_phoneCode.disabled = !0),
          this.def_time <= 0 &&
            ((this.bt_phoneCode.disabled = !1),
            Laya.timer.clear(this, this.timeCountDown),
            (this.bt_phoneCode.label = "获取验证码"),
            (this.def_time = 60));
      }),
      (t.prototype.registerSuccess = function (e) {
        console.log(e),
          0 == e.code
            ? (ToastView.toastView("注册成功,请重新登录"),
              Laya.timer.clear(this, this.timeCountDown),
              (this.tab_loginReg.selectedIndex = 0),
              (this.tx_phoneNum.text = ""),
              (this.tx_pwd.text = ""),
              (this.tx_aginspassword.text = ""),
              (this.tx_verificateCode.text = ""),
              (this.bt_phoneCode.label = "获取验证码"),
              (this.bt_phoneCode.disabled = !1),
              this.initView())
            : ToastView.toastView(e.msg);
      }),
      (t.prototype.onForgetFn = function () {
        (this.list_more_phone.visible = !1),
          (this.registerView.visible = !1),
          (this.loginView.visible = !1),
          (this.forgetpwdView.visible = !0),
          (this.tab_loginReg.visible = !1);
      }),
      (t.prototype.forgetBackFn = function () {
        (this.registerView.visible = !1),
          (this.forgetpwdView.visible = !1),
          (this.loginView.visible = !0),
          (this.tab_loginReg.visible = !0);
      }),
      (t.prototype.onRemmberScrectFn = function () {}),
      (t.prototype.submitpwdFn = function () {
        var e = this.phone.text,
          t = this.tx_xinmima.text,
          i = this.tx_xinmimas.text,
          o = this.tx_codes.text;
        if (
          (console.log("账号" + e),
          console.log("密码" + t),
          console.log("确认密码" + i),
          console.log("验证码" + o),
          e)
        )
          if (t)
            if (i)
              if (o) {
                var s = new Ajax(),
                  a = {
                    mobile: e,
                    pwd: Md5.hashStr(t),
                    captcha: this.tx_codes.text,
                  };
                (s.success = this.submitpwdSuccess),
                  s.postForm(
                    Environment.apiHost + "/user-service/user/resetPwd",
                    a
                  );
              } else ToastView.toastView("请输入验证码");
            else ToastView.toastView("请输入确认密码");
          else ToastView.toastView("请输入密码");
        else ToastView.toastView("请输入账号");
      }),
      (t.prototype.submitpwdSuccess = function (e) {
        console.log(e),
          0 == e.code
            ? ToastView.toastView("修改成功")
            : ToastView.toastView(e.msg);
      }),
      (t.prototype.modifypwdCodeFn = function () {
        var e = this.phone.text;
        if (this.verifyPhoneNumber(e)) {
          var t = this.tx_captcha2.text;
          if (!t)
            return (
              (this.img_captcha2.skin =
                Environment.apiHost +
                "/user-service/user/captchaImg?moblie=" +
                e +
                "&c=" +
                Math.random()),
              void ToastView.toastView("请输入图形验证码")
            );
          var i = new Ajax(this),
            o = { mobile: e, captcha: t };
          (i.success = this.modifypwdCodeSuccess),
            i.postForm(Environment.apiHost + "/user-service/user/captcha", o);
        } else ToastView.toastView("手机号格式错误");
      }),
      (t.prototype.modifypwdCodeSuccess = function (e) {
        console.log(e),
          0 == e.code
            ? (this.tx_codes.text = e.data)
            : ToastView.toastView(e.msg);
      }),
      (t.prototype.verificateCodeFn = function () {
        var e = this.tx_phoneNum.text;
        if (this.verifyPhoneNumber(e)) {
          var t = this.tx_captcha.text;
          if (!t)
            return (
              (this.img_captcha.skin =
                Environment.apiHost +
                "/user-service/user/captchaImg?moblie=" +
                e +
                "&c=" +
                Math.random()),
              void ToastView.toastView("请输入图形验证码")
            );
          if (this.verifyPhoneNumber(e)) {
            var i = new Ajax(this),
              o = { mobile: e, captcha: t };
            (i.success = this.verificateCodeSuccess),
              i.postForm(
                Environment.apiHost + "/user-service/user/captchaReg",
                o
              );
          }
        } else ToastView.toastView("手机号格式错误");
      }),
      (t.prototype.verificateCodeSuccess = function (e) {
        console.log(e),
          0 == e.code
            ? (Laya.timer.loop(1e3, this, this.timeCountDown),
              (this.tx_verificateCode.text = e.data))
            : ToastView.toastView(e.msg);
      }),
      (t.prototype.changeRegImage = function () {
        var e = this.tx_phoneNum.text;
        this.verifyPhoneNumber(e)
          ? ((this.btn_getCaptcha.visible = !1),
            (this.img_captcha.visible = !0),
            (this.img_captcha.skin =
              Environment.apiHost +
              "/user-service/user/captchaImg?moblie=" +
              e +
              "&c=" +
              Math.random()))
          : ToastView.toastView("手机号格式错误");
      }),
      (t.prototype.changeImage = function () {
        var e = this.phone.text;
        this.verifyPhoneNumber(e)
          ? ((this.btn_getCaptcha2.visible = !1),
            (this.img_captcha2.visible = !0),
            (this.img_captcha2.skin =
              Environment.apiHost +
              "/user-service/user/captchaImg?moblie=" +
              e +
              "&c=" +
              Math.random()))
          : ToastView.toastView("手机号格式错误");
      }),
      (t.prototype.verifyPhoneNumber = function (e) {
        return (
          !!/^(1\d{10})$/.test(e) ||
          (ToastView.toastView("请输入有效的手机号"), !1)
        );
      }),
      t
    );
  })(ui.RegDialogUI);
